package com.star.spring.easyexcel.convert;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;

public class LocalTimeConvert implements Converter<LocalTime> {

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext context) throws Exception {
        LocalTime localTime = (LocalTime) context.getValue();
        if (localTime == null) {
            return new WriteCellData<>();
        }
        String format = localTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
        return new WriteCellData<>(format);
    }
}
